package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @author iTaotao
 * @version 1.0
 * @Description
 * @createTime 2023年08月03日 14:16:00
 */
@Mapper
public interface OrderMapper {
    /**
     * 催单
     *
     * @param id id
     */
    @Select("select * from orders where id= #{id} and user_id = #{userId}")
    void reminder(Long id);


    /**
     * 历史订单分页
     *
     * @param order 订单
     * @return {@link Page}<{@link Orders}>
     */
    Page<Orders> selectPage(Orders order);


    /**
     * 插入订单
     *
     * @param orders 订单
     */
    void insert(Orders orders);

    /**
     * 付款通知
     *
     * @param number 订单
     * @param status 状态
     */
    @Update("update orders set status= #{status} , pay_status = 1 ,checkout_time = now() where number = #{number} ")
    void payNotification(String number, Integer status);

    /**
     * 选择订单id
     *
     * @param
     * @return {@link Orders}
     */
    @Select("select * from orders where id = #{id} and user_id = #{userId} ")
    Orders selectOrderById(Orders orders);

    /**
     * 更新ststus
     *
     * @param orders 订单
     */
    void updateStstus(Orders orders);

    @Select("select * from orders where id = #{id}")
    Orders selectById(Long id);


    Integer updateStatusByStatusAndBeforeOrderTime(Integer statusResult, Integer statusQuery, LocalDateTime time);

    Integer updateStatuByStatus(Integer statusResult, Integer statusQuery);

    @Select("select * from orders where number = #{number}")
    Orders selectByNumber(String number);

    List<Map<String, Object>> selectTurnoverStatistics(LocalDate begin, LocalDate end);

    /**
     * 选择订单统计
     *
     * @param begin 开始
     * @param end   结束
     * @return {@link List}<{@link Map}<{@link String}, {@link Object}>>
     */
    List<Map<String, Object>> selectOrdersStatistics(LocalDate begin, LocalDate end);

    /**
     * 选择数量与日期
     *
     * @param item 项
     * @return {@link Integer}
     */
    Integer selectCountWithDate(String item);

    List<Map<String, Object>> selectTop10(LocalDate begin, LocalDate end);
}
